/*Joseph A. Coll
RCV AP MVC Check
7/23/2025*/

*Load data
use "G:\My Drive\Backup 08202022\Working Papers\RCV and AP\Data and Methods\RCV AP Data Cleaned.dta", clear
cd "G:\My Drive\Backup 08202022\Working Papers\RCV and AP\Tables and Figures RCV AP"

********************************************************************************	
********************************************************************************
********************************************************************************
**# Attention Checks
********************************************************************************
********************************************************************************
********************************************************************************	
fre mvc_correct_total fmc_correct_total
drop if mvc_correct_total != 3

********************************************************************************	
********************************************************************************
********************************************************************************
**#Main Analyses and Figures
********************************************************************************
********************************************************************************
********************************************************************************	

********************************************************************************
*Does Treatment Affect Affective Polarization
********************************************************************************
*FT
	*Affective polarization 
	reg ap_ft_change i.treatment
	estimates store ap_ft_change_mvc
	margins, at(treatment=(1(1)3)) post 
	coefplot, vertical ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xlabel(1 `" "Plurality" "Comp."' 2 `" "RCV" "Comp."'  3 `" "RCV" "Comp." "& Endorse"' ) ///
	xscale(r(1.25 2.25)) ///
	title("", size(medium)) ///
	ytitle("Affective Polarization {&Delta}") ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	yscale(r(-.035 .035)) ///
	ylabel(-.03(.01).03) ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
		cond(@pval<.05, string(@b,"%9.3f") + "***", ///
		cond(@pval<.01, string(@b,"%9.3f") + "**", ///
		cond(@pval<.001, string(@b,"%9.3f") + "*", ///
		string(@pval,"%9.3fThe")))))) ///
	name(ap_ft_change_mvc, replace) 
	graph export ap_ft_change_mvc.png, replace
	
	*In group
	reg ap_ft_ip_change  i.treatment
	estimates store ap_ft_ip_change_mvc
	margins, at(treatment=(1(1)3)) post
	coefplot, vertical ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xlabel(1 `" "Plurality" "Comp."' 2 `" "RCV" "Comp."'  3 `" "RCV" "Comp." "& Endorse"' ) ///
	xscale(r(1.25 2.25)) ///
	title("", size(medium)) ///
	ytitle("In-Group Affect {&Delta}") ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	yscale(r(-.035 .035)) ///
	ylabel(-.03(.01).03) ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
		cond(@pval<.05, string(@b,"%9.3f") + "***", ///
		cond(@pval<.01, string(@b,"%9.3f") + "**", ///
		cond(@pval<.001, string(@b,"%9.3f") + "*", ///
		string(@pval,"%9.3fThe")))))) ///
	name(ap_ft_ip_change_mvc, replace) 
	graph export ap_ft_ip_change_mvc.png, replace	
	
	*Outgroup
	reg ap_ft_op_change  i.treatment 
	estimates store ap_ft_op_change_mvc
	margins, at(treatment=(1(1)3)) post
	coefplot, vertical ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xlabel(1 `" "Plurality" "Comp."' 2 `" "RCV" "Comp."'  3 `" "RCV" "Comp." "& Endorse"' ) ///
	xscale(r(1.25 2.25)) ///
	title("", size(medium)) ///
	ytitle("Out-Group Affect {&Delta}") ///
	yscale(r(-.035 .035)) ///
	ylabel(-.03(.01).03) ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
		cond(@pval<.05, string(@b,"%9.3f") + "***", ///
		cond(@pval<.01, string(@b,"%9.3f") + "**", ///
		cond(@pval<.001, string(@b,"%9.3f") + "*", ///
		string(@pval,"%9.3fThe")))))) ///
	name(ap_ft_op_change_mvc, replace) 
	graph export ap_ft_op_change_mvc.png, replace	
	
	coefplot ap_ft_change_mvc ap_ft_ip_change_mvc ap_ft_op_change_mvc, ///
	drop(_cons) xline(0) ///
	xscale(r(-.015 .015)) ///
	xlabel(-.01(.01).01) ///
	scheme(plotplain) ///
	legend(order(2 "In- minus Out-Ideology" 4 "In-Ideology" 6 "Out-Ideology") row(1) pos(6)) ///
	title("Feeling Thermometer") ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
	cond(@pval<.001, string(@b,"%9.3f") + "***", ///
	cond(@pval<.01, string(@b,"%9.3f") + "**", ///
	cond(@pval<.05, string(@b,"%9.3f") + "*", ///
	string(@pval,"%9.3f")))))) ///
	mlabpos(12) ///
	mlabgap(2.5) ///
	name(coef_ft_mvc, replace)

	graph combine ap_ft_change_mvc ap_ft_ip_change_mvc ap_ft_op_change_mvc, ///
	ycommon xcommon ///
	rows(1) ///
	name(ft_combined_mvc, replace)
	graph export ft_combined_mvc.png, replace 

*Traits
	*Affective polarization
	reg ap_traits_change  i.treatment
	estimates store ap_traits_change_mvc
	margins, at(treatment=(1(1)3)) post
	coefplot, vertical ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xlabel(1 `" "Plurality" "Comp."' 2 `" "RCV" "Comp."'  3 `" "RCV" "Comp." "& Endorse"' ) ///
	xscale(r(1.25 2.25)) ///
	title("", size(medium)) ///
	ytitle("Affective Polarization {&Delta} ") ///
	yscale(r(-.04 .04)) ///
	ylabel(-.03(.01).03) ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
		cond(@pval<.05, string(@b,"%9.3f") + "***", ///
		cond(@pval<.01, string(@b,"%9.3f") + "**", ///
		cond(@pval<.001, string(@b,"%9.3f") + "*", ///
		string(@pval,"%9.3fThe")))))) ///
	name(ap_traits_change_mvc, replace) 
	graph export ap_traits_change_mvc.png, replace
	
	*In group
	reg ap_traits_ip_change  i.treatment
	estimates store ap_traits_ip_change_mvc
	margins, at(treatment=(1(1)3)) post
	coefplot, vertical ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xlabel(1 `" "Plurality" "Comp."' 2 `" "RCV" "Comp."'  3 `" "RCV" "Comp." "& Endorse"' ) ///
	xscale(r(1.25 2.25)) ///
	title("", size(medium)) ///
	ytitle("In-Group Affect {&Delta} ") ///
	yscale(r(-.04 .04)) ///
	ylabel(-.03(.01).03) ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
		cond(@pval<.05, string(@b,"%9.3f") + "***", ///
		cond(@pval<.01, string(@b,"%9.3f") + "**", ///
		cond(@pval<.001, string(@b,"%9.3f") + "*", ///
		string(@pval,"%9.3fThe")))))) ///
	name(ap_traits_ip_change_mvc, replace) 
	graph export ap_traits_ip_change_mvc.png, replace
	
	*Out group
	reg ap_traits_op_change i.treatment
	estimates store ap_traits_op_change_mvc
	margins, at(treatment=(1(1)3)) post
	coefplot, vertical ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xlabel(1 `" "Plurality" "Comp."' 2 `" "RCV" "Comp."'  3 `" "RCV" "Comp." "& Endorse"' ) ///
	xscale(r(1.25 2.25)) ///
	title("", size(medium)) ///
	ytitle("Out-Group Affect {&Delta} ") ///
	yscale(r(-.04 .04)) ///
	ylabel(-.03(.01).03) ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
		cond(@pval<.05, string(@b,"%9.3f") + "***", ///
		cond(@pval<.01, string(@b,"%9.3f") + "**", ///
		cond(@pval<.001, string(@b,"%9.3f") + "*", ///
		string(@pval,"%9.3fThe")))))) ///
	name(ap_traits_op_change_mvc, replace) 
	graph export ap_traits_op_change_mvc.png, replace
	
	coefplot ap_traits_change_mvc ap_traits_ip_change_mvc ap_traits_op_change_mvc, ///
	drop(_cons) xline(0) ///
	xscale(r(-.015 .015)) ///
	xlabel(-.01(.01).01) ///
	scheme(plotplain) ///
	legend(order(2 "In- minus Out-Ideology" 4 "In-Ideology" 6 "Out-Ideology") row(1) pos(6)) ///
	title("Traits") ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
	cond(@pval<.001, string(@b,"%9.3f") + "***", ///
	cond(@pval<.01, string(@b,"%9.3f") + "**", ///
	cond(@pval<.05, string(@b,"%9.3f") + "*", ///
	string(@pval,"%9.3f")))))) ///
	mlabpos(12) ///
	mlabgap(2.5) ///
	name(coef_t_mvc, replace)

	graph combine ap_traits_change_mvc ap_traits_ip_change_mvc ap_traits_op_change_mvc, ///
	ycommon xcommon ///
	rows(1) ///
	name(traits_combined_mvc, replace)
	graph export traits_combined_mvc.png, replace 
	
	
	graph combine ap_ft_change_mvc ap_ft_ip_change_mvc ap_ft_op_change_mvc ///
	 ap_traits_change_mvc ap_traits_ip_change_mvc ap_traits_op_change_mvc, ///
	ycommon xcommon ///
	rows(2) ///
	name(both_combined_mvc, replace)
	graph export both_combined_mvc.png, replace 

*Feeling Thermometer table
	esttab ap_ft_change_mvc ap_ft_ip_change_mvc ap_ft_op_change_mvc ///
	using apft_mvc.tex, replace ///
	cells(b(star fmt(3)) se(fmt(3) par) ) starlevels( * 0.05 ** 0.01 *** 0.001) ///
	label ///
	stat(r2 N, fmt(2 0) label("R$^2$" "\textit{N}")) ///
	nodepvars nobase noomitted interaction(" x ") ///
	drop() ///
	style(tex) compress ///
	title("Electoral System, Candidate Communication, and Change in Partisan Affect (Feeling Thermometer)\label{tab:apftmvc}") ///
	mlabel("Affective Polarization" "In-Group" "Out-Group") 
		
*Traits table
	esttab ap_traits_change_mvc ap_traits_ip_change_mvc ap_traits_op_change_mvc ///
	using apt_mvc.tex, replace ///
	cells(b(star fmt(3)) se(fmt(3) par) ) starlevels( * 0.05 ** 0.01 *** 0.001) ///
	label ///
	stat(r2 N, fmt(2 0) label("R$^2$" "\textit{N}")) ///
	nodepvars nobase noomitted interaction(" x ") ///
	drop() ///
	style(tex) compress ///
	title("Electoral System, Candidate Communication, and Change in Partisan Affect (Traits)\label{tab:aptmvc}") ///
	mlabel("Affective Polarization" "In-Group" "Out-Group") 	
	